package cn.gz.ibix.load;

import com.google.gson.JsonElement;

import java.util.List;
import java.util.Map;

import cn.gz.ibix.bean.Food;
import io.reactivex.Flowable;
import io.reactivex.functions.Function;

/**
 * 项目名称：QiYiChuAPP
 * <br>类描述：
 * <br>创建人：htliu
 * <br>创建时间：2018/3/24 16:04
 * <br>修改人:
 * <br>修改时间：2018/3/24 16:04
 * <br>修改备注：
 * <br>@version
 */
public class FoodLoader extends BaseDataLoader<Food> {

    private long menuID;

    public FoodLoader(long menuID) {
        this.menuID = menuID;
    }

    @Override
    protected String api() {
        return "/restaurant/listFood";
    }

    @Override
    protected List<Food> processData(JsonElement data) {
   /*     return Flowable.fromIterable(data.getAsJsonObject().get("data").getAsJsonArray())
                .map(new Function<JsonElement, Food>() {
                    @Override
                    public Food apply(JsonElement element) throws Exception {
                        return gson.fromJson(element, Food.class);
                    }
                }).toList().blockingGet();*/
        return Flowable.range(page * pageSize, pageSize).map(new Function<Integer, Food>() {
            @Override
            public Food apply(Integer integer) throws Exception {
                Food food = new Food();
                food.setName("this is " + integer);
                return food;
            }
        }).toList().blockingGet();
    }

    @Override
    protected void editParam(Map<String, String> params) {
        params.put("menuID", String.valueOf(menuID));
        params.put("restaurantID", "1");
    }


}
